using System;
using System.Collections.Generic;
using System.Text;
using MacomberMap.Common.Events;
using System.Windows.Forms;
using MacomberMap.Common.Database_Interface.CIM.One_Line_Interface;

namespace MacomberMap.Common.Database_Interface.CIM.Events
{
    /// <summary>
    /// This class holds information on an error when an Xml component has more than 1 parent.
    /// </summary>
    public class MM_Event_MoreParents: MM_Event
    {
        #region Variable declaration
        /// <summary>The Xml component that was assigned more than one parent</summary>
        public MM_OneLine_XmlComponent Element;

        /// <summary>The element's existing parent</summary>
        public MM_OneLine_XmlComponent OldParent;

        /// <summary>The element's new parent</summary>
        public MM_OneLine_XmlComponent NewParent;
        #endregion

        #region Initialization
        /// <summary>
        /// Initialize the event
        /// </summary>
        /// <param name="Element"></param>
        /// <param name="OldParent"></param>
        /// <param name="NewParent"></param>
        public MM_Event_MoreParents(MM_OneLine_XmlComponent Element, MM_OneLine_XmlComponent OldParent, MM_OneLine_XmlComponent NewParent)
        {
            this.Element = Element;
            this.OldParent = OldParent;
            this.NewParent = NewParent;
        }
        #endregion

        /// <summary>
        /// Build a list view item for the error
        /// </summary>
        /// <returns></returns>
        public override ListViewItem BuildListViewItem()
        {
            ListViewItem NewItem = new ListViewItem(Element.Name);
            NewItem.SubItems.Add(this.EventState.ToString());
            NewItem.SubItems.Add(TimeText);
            NewItem.ImageIndex = EventType.Index;
            return NewItem;
        }

        /// <summary>
        /// Update the list view item
        /// </summary>
        /// <param name="lvItem"></param>
        public override void UpdateListViewItem(ListViewItem lvItem)
        {
            lvItem.SubItems[0].Text = Element.Name;
            lvItem.SubItems[1].Text = EventState.ToString();
            lvItem.SubItems[2].Text = TimeText;
        }

        /// <summary>
        /// Display details of the event
        /// </summary>
        /// <param name="OutParent"></param>
        public override void DisplayDetails(Control OutParent)
        {
            TreeView tvOut = new TreeView();
            tvOut.Dock = DockStyle.Fill;
            this.AddNodeItem("Element", Element, tvOut.Nodes);
            this.AddNodeItem("Old Parent", OldParent, tvOut.Nodes);
            this.AddNodeItem("New Parent", NewParent, tvOut.Nodes);
            tvOut.Nodes[0].EnsureVisible();
            OutParent.Controls.Add(tvOut);
        }

        /// <summary>
        /// Add menu items for the event
        /// </summary>
        /// <param name="OutMenu"></param>
        public override void AddMenuItems(ContextMenuStrip OutMenu)
        {
            //throw new Exception("The method or operation is not implemented.");
        }

        /// <summary>
        /// Compare the event ot others
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override int CompareTo(object obj)
        {
            return String.Compare(Element.Name, (obj as MM_Event_MoreParents).Element.Name, true);                
        }
    }
}
